//
//  UserDataManager.h
//  firebkball
//
//  Created by ren jian on 18/5/28.
//
//

#ifndef UserDataManager_h
#define UserDataManager_h

#include "DataStorageTool.h"
#include "MyConst.h"
#include "MyFunction.h"

USING_NS_CC;
using namespace std;

class User : public Ref
{
public:
    int coin;   // 当前投币数
    int startCoinNumber; //一局需要的硬币数
    int scoreTop[5];    // 历史分数排行榜
    int rewardList[4];  // 奖励列表
    
    User(){
        coin = 0;
        // 一局需要的硬币数
        startCoinNumber = DataStorageTool::getIntValue(MyConst::KEY_GAME_START_COIN_NUMBER);
        if (startCoinNumber==0) {
            startCoinNumber = 2;
            DataStorageTool::saveIntValue(MyConst::KEY_GAME_START_COIN_NUMBER, startCoinNumber);
        }
        // 分数
        for(int i=0; i<5; i++)
        {
            int l_s = DataStorageTool::getIntValue(StringUtils::format("%s%d", MyConst::KEY_USER_TOP.c_str(), i+1));
            scoreTop[i] = l_s;
        }
        // 奖励分数
        for(int i=0; i<4; i++)
        {
            int l_r = DataStorageTool::getIntValue(StringUtils::format("%s%d", MyConst::KEY_USER_REWARD.c_str(), i));
            if (l_r==0) {
                l_r = 40-i*10;
                DataStorageTool::saveIntValue(StringUtils::format("%s%d", MyConst::KEY_USER_REWARD.c_str(), i), l_r);
            }
            rewardList[i] = l_r;
            CCLOG("%d", l_r);
        }
    };
    ~User(){};
    
    int getTodayCoin();
    void setTodayCoin();
    
    //刷新分数排行榜
    void refreshScoreTop(int _newScore);
};

class BattleData : public Ref
{
public:
    // 空心球分数
    int score_kongxin;
    // 篮板球分数
    int score_lanban;
    // 高射球分数
    int score_gaoshe;
    // 当前分数
    int score;
    // 连续空心球
    int hollowBallNumber;
    
    BattleData(){
        score = 0;
        score_gaoshe = 3;
        score_lanban = 3;
        score_kongxin = 2;
        hollowBallNumber = 0;
    }
    
    // 重置
    void resethData(){
        score = 0;
        hollowBallNumber = 0;
    };
    
    // 计算分数
    void calculateTheScore(bool _isKongxin, bool _isGaoshe, bool _isLanban);
};

class UserDataManager : public Ref
{
public:
    User    *userData;
    BattleData *battleData;
    
    static UserDataManager *getInstance();
    UserDataManager();
    ~UserDataManager();
    
    // 添加一个投币数
    void addCoin(int _number);
};

#endif /* UserDataManager_h */
